<template>
  <div class="confirm-modal-overlay" @click.self="cancel">
    <div class="confirm-modal-container">
      <div class="confirm-modal-header" v-if="title">
        <h3>{{ title }}</h3>
      </div>

      <div class="confirm-modal-body">
        <p>{{ message }}</p>
      </div>

      <div class="confirm-modal-footer">
        <button class="confirm-modal-btn cancel-btn" @click="cancel">
          {{ cancelText }}
        </button>
        <button class="confirm-modal-btn confirm-btn" @click="confirm">
          {{ confirmText }}
        </button>
      </div>
    </div>
  </div>
</template>

<script setup>
const props = defineProps({
  title: {
    type: String,
    default: '确认操作'
  },
  message: {
    type: String,
    required: true
  },
  cancelText: {
    type: String,
    default: '取消'
  },
  confirmText: {
    type: String,
    default: '确认'
  }
})

const emit = defineEmits(['confirm', 'cancel'])

const confirm = () => {
  emit('confirm')
}

const cancel = () => {
  emit('cancel')
}
</script>

<style scoped>
.confirm-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.confirm-modal-container {
  background-color: var(--card-bg);
  border-radius: 8px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.confirm-modal-header {
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.confirm-modal-header h3 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text-color);
}

.confirm-modal-body {
  padding: 1.5rem;
}

.confirm-modal-body p {
  margin: 0;
  line-height: 1.5;
  color: var(--text-color);
}

.confirm-modal-footer {
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: flex-end;
  gap: 1rem;
  border-top: 1px solid var(--border-color);
}

.confirm-modal-btn {
  padding: 0.5rem 1.2rem;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s ease;
  border: none;
}

.cancel-btn {
  background-color: var(--card-bg);
  color: var(--text-color);
  border: 1px solid var(--border-color);
}

.cancel-btn:hover {
  background-color: var(--hover-bg);
}

.confirm-btn {
  background-color: var(--danger-color);
  color: white;
}

.confirm-btn:hover {
  opacity: 0.9;
}
</style>